<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/7
 * Time: 16:53
 */


ini_set('display_errors', 1);
error_reporting(E_ALL);
class We7_testModuleWxapp extends WeModuleWxapp {

	private $route;
	private $container;
	public function __construct()
	{
		$container = include __DIR__.'/bootstrap.php';
		$this->route = include __DIR__.'/routes/wxapp.php';
		$this->container = $container;
	}

	public function __call($name, $arguments)
	{

		ob_clean(); //调试模式下 清除外部框架 的错误输出 要不会报错
		$container  = $this->container;
		/**
		 * @var $request \Psr\Http\Message\ServerRequestInterface
		 */
		$name = strtolower($name);
		$name = str_replace('dopage', '', $name);
		$request = $container->get('request');
		$query = $request->getQueryParams();
		$request = $request->withUri(new \Zend\Diactoros\Uri('/'.$name))->withQueryParams($query);
		// 把do 操作转成rest  风格
		$response = $this->route->dispatch($request, $container->get('response'));
		$container->get('emitter')->emit($response);
	}
}